package com.fenyin.samples.study.quartz;  

import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.Job;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleTrigger;
import org.quartz.TriggerUtils;
  
public class PublishSchedulerListener implements Job{
	private static final Log log = LogFactory.getLog(PublishSchedulerListener.class);
	
	public void execute(JobExecutionContext context)throws JobExecutionException {
		try {
			log.info("scheduler listener:begin");
			Date runDate = TriggerUtils.getDateOf(0, 34, 22);
			JobDetail jobDetail = new JobDetail("scan_directory_job", Scheduler.DEFAULT_GROUP,ScanDirectoryJob.class);
			jobDetail.getJobDataMap().put("SCAN_DIR", "D:\\temp");
			
			SimpleTrigger trigger = new SimpleTrigger("scan_directory_trigger", Scheduler.DEFAULT_GROUP, runDate, 
	                null, 
	                10, 
	                1 * 1000L);
			context.getScheduler().scheduleJob(jobDetail, trigger);
			log.info("scheduler listener:end");
		} catch (SchedulerException e) {
			log.error("execute error", e);
		}
	}

}
